package com.xing.config;

import org.springframework.web.servlet.HandlerInterceptor;

//拦截器
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception {
        //登录成功之后，将用户的信息放置到session
        Object loginUser = request.getSession().getAttribute("loginUser");
        if (loginUser == null) {
            //没有登录，而是直接进入的首页，肯定是不让进的
            request.setAttribute("msg", "没有权限，请先登录");
            request.getRequestDispatcher("/index.html").forward(request, response);
            return false;
        } else {
            //本次访问巧登录
            return true;
        }
    }
}
